﻿using System;

namespace ForgeCraft
{
    public class CmdRepeat : Command
    {
        public override string name { get { return "reapeat"; } }
        public override string shortcut { get { return "m"; } }
        public override string type { get { return "general"; } }
        public override bool consoleUsable { get { return false; } }
        public override Permission defaultRank { get { return Permission.Guest; } }
        public CmdRepeat() { }

        public override void Use(Player p, string message)
        {
            if (p.lastCMD == "") { p.Message("No commands used yet."); return; }
            if (p.lastCMD.Length > 5)
                if (p.lastCMD.Substring(0, 6) == "static") { p.Message("Can't repeat static"); return; }

            p.Message("Using " + Color.Help + "/" + p.lastCMD);

            if (p.lastCMD.IndexOf(' ') == -1)
            {
                Command.all.Find(p.lastCMD).Use(p, "");
            }
            else
            {
                Command.all.Find(p.lastCMD.Substring(0, p.lastCMD.IndexOf(' '))).Use(p, p.lastCMD.Substring(p.lastCMD.IndexOf(' ') + 1));
            }
        }
        public override void Help(Player p)
        {
            p.Message(Color.Aqua + "/repeat " + Color.Help + "- Repeats the last used command.");
        }
    }
}